﻿package core.resource
{
    import flash.events.*;
    import flash.system.*;
    import flash.text.*;
    import flash.utils.*;

    public class fpsBox extends TextField
    {
        private var timer:Timer;
        protected var frames:uint = 0;
        protected var format:TextFormat;

        public function fpsBox()
        {
            this.format = new TextFormat();
            this.timer = new Timer(1000);
            this.format.font = "arial";
            this.format.color = 0;
            this.format.size = 10;
            this.autoSize = TextFieldAutoSize.LEFT;
            this.defaultTextFormat = this.format;
            this.text = "-- FPS";
            this.timer.addEventListener(TimerEvent.TIMER, this.tick);
            this.addEventListener(Event.ENTER_FRAME, this.everyFrame, false, 0, true);
            this.timer.start();
            return;
        }// end function

        public function everyFrame(event:Event) : void
        {
            var _loc_2:String = this;
            var _loc_3:* = this.frames + 1;
            _loc_2.frames = _loc_3;
            return;
        }// end function

        protected function tick(event:TimerEvent) : void
        {
            this.text = this.frames + " FPS " + Number(System.totalMemory / 1024 / 1024).toFixed(2) + " MB";
            this.frames = 0;
            return;
        }// end function

    }
}
